home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1996
/
MacHack 1996.toast
/
Hacks
/
Hacks ’95
/
TrashHack
/
TrashHackInstaller.c
< prev
next >
Wrap
Text File
|
1995-06-24
|
2KB
|
111 lines
// DrawStringPatch.a
// patches DrawString to draw the size of the trash instead of "Trash"
#include <GestaltEqu.h>
#include <Memory.h>
#include <OSUtils.h>
#include <Resources.h>
#include <Traps.h>
#include <Types.h>
// turn debugs off
#define DebugStr(x)
#define kDrawStringTrap 0xa884
#define kJumpAbsoluteInstr 0x4ef9
#define rPatchResourceType 'DRWS'
#define rPatchResourceID 0
pascal void
MAIN (void)
{
Boolean foundJump;
long i;
long codeSize;
long drawStringAddress;
unsigned short *code;
Handle drawStringPatchHandle;
// GET CURRENT ADDRESS OF DRAWSTRING TRAP
// figure out where DrawString goes now
drawStringAddress = NGetTrapAddress (kDrawStringTrap, ToolTrap);
// do we have it?
if (drawStringAddress == NGetTrapAddress (_Unimplemented, ToolTrap))
{
DebugStr ("\p DrawString not implemented on this machine");
return;
}
// LOAD DRAWSTRING PATCH CODE RESOURCE
// make sure our resource goes into the system heap
SetZone (SystemZone ());
// get our patch code resource
drawStringPatchHandle = Get1Resource (rPatchResourceType, rPatchResourceID);
// did we get it?
if (drawStringPatchHandle == nil)
{
DebugStr ("\p Can't find patch code resource");
return;
}
// lock it down
HNoPurge (drawStringPatchHandle);
HLock (drawStringPatchHandle);
// PATCH JUMP INSTRUCTION
// take an instruction pointer into the code
code = (unsigned short *) *drawStringPatchHandle;
// say we haven't found the jump instruction
foundJump = false;
// figure out how many WORDS are in the code resource
codeSize = GetHandleSize (drawStringPatchHandle) << 1;
// for each word in the code resource
for (i = 0; i < codeSize; i++)
{
// is it our jump instruction?
if (code [i] == kJumpAbsoluteInstr)
{
// patch in the current NewGWorld trap address
code [i + 1] = drawStringAddress >> 16;
code [i + 2] = drawStringAddress & 0xffff;
// we're done
foundJump = true;
break;
}
}
// SET DRAWSTRING TRAP ADDRESS
// check we found the jump instruction
if (foundJump)
{
// install our code in the system heap
DetachResource (drawStringPatchHandle);
// set the trap address
NSetTrapAddress ((UniversalProcPtr) *drawStringPatchHandle, kDrawStringTrap, ToolTrap);
}
else
{
DebugStr ("\p Couldn't find jump instruction");
// dump the resource
ReleaseResource (drawStringPatchHandle);
}
}